<!doctype html>
<html class="no-js" lang="en, zh-CN" data-content_root="../../">
  <head><meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1"/>
    <meta name="color-scheme" content="light dark"><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<link rel="index" title="Index" href="../../genindex.html" /><link rel="search" title="Search" href="../../search.html" /><link rel="next" title="Javet Performance" href="performance.html" /><link rel="prev" title="Memory Management" href="memory_management.html" />

    <link rel="shortcut icon" href="../../_static/logo.ico"/><!-- Generated with Sphinx 7.2.6 and Furo 2023.09.10 -->
        <title>Modularization - Javet 3.0.0 documentation</title>
      <link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=a746c00c" />
    <link rel="stylesheet" type="text/css" href="../../_static/styles/furo.css?v=135e06be" />
    <link rel="stylesheet" type="text/css" href="../../_static/tabs.css?v=4c969af8" />
    <link rel="stylesheet" type="text/css" href="../../_static/styles/furo-extensions.css?v=36a5483c" />
    <link rel="stylesheet" type="text/css" href="../../_static/css/custom.css?v=c2631171" />
    
    


<style>
  body {
    --color-code-background: #f8f8f8;
  --color-code-foreground: black;
  
  }
  @media not print {
    body[data-theme="dark"] {
      --color-code-background: #202020;
  --color-code-foreground: #d0d0d0;
  
    }
    @media (prefers-color-scheme: dark) {
      body:not([data-theme="light"]) {
        --color-code-background: #202020;
  --color-code-foreground: #d0d0d0;
  
      }
    }
  }
</style></head>
  <body>
    
    <script>
      document.body.dataset.theme = localStorage.getItem("theme") || "auto";
    </script>
    

<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
  <symbol id="svg-toc" viewBox="0 0 24 24">
    <title>Contents</title>
    <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 1024 1024">
      <path d="M408 442h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm-8 204c0 4.4 3.6 8 8 8h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56zm504-486H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 632H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM115.4 518.9L271.7 642c5.8 4.6 14.4.5 14.4-6.9V388.9c0-7.4-8.5-11.5-14.4-6.9L115.4 505.1a8.74 8.74 0 0 0 0 13.8z"/>
    </svg>
  </symbol>
  <symbol id="svg-menu" viewBox="0 0 24 24">
    <title>Menu</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-menu">
      <line x1="3" y1="12" x2="21" y2="12"></line>
      <line x1="3" y1="6" x2="21" y2="6"></line>
      <line x1="3" y1="18" x2="21" y2="18"></line>
    </svg>
  </symbol>
  <symbol id="svg-arrow-right" viewBox="0 0 24 24">
    <title>Expand</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-chevron-right">
      <polyline points="9 18 15 12 9 6"></polyline>
    </svg>
  </symbol>
  <symbol id="svg-sun" viewBox="0 0 24 24">
    <title>Light mode</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather-sun">
      <circle cx="12" cy="12" r="5"></circle>
      <line x1="12" y1="1" x2="12" y2="3"></line>
      <line x1="12" y1="21" x2="12" y2="23"></line>
      <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
      <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
      <line x1="1" y1="12" x2="3" y2="12"></line>
      <line x1="21" y1="12" x2="23" y2="12"></line>
      <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
      <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
    </svg>
  </symbol>
  <symbol id="svg-moon" viewBox="0 0 24 24">
    <title>Dark mode</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-moon">
      <path stroke="none" d="M0 0h24v24H0z" fill="none" />
      <path d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454z" />
    </svg>
  </symbol>
  <symbol id="svg-sun-half" viewBox="0 0 24 24">
    <title>Auto light/dark mode</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-shadow">
      <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
      <circle cx="12" cy="12" r="9" />
      <path d="M13 12h5" />
      <path d="M13 15h4" />
      <path d="M13 18h1" />
      <path d="M13 9h4" />
      <path d="M13 6h1" />
    </svg>
  </symbol>
</svg>

<input type="checkbox" class="sidebar-toggle" name="__navigation" id="__navigation">
<input type="checkbox" class="sidebar-toggle" name="__toc" id="__toc">
<label class="overlay sidebar-overlay" for="__navigation">
  <div class="visually-hidden">Hide navigation sidebar</div>
</label>
<label class="overlay toc-overlay" for="__toc">
  <div class="visually-hidden">Hide table of contents sidebar</div>
</label>



<div class="page">
  <header class="mobile-header">
    <div class="header-left">
      <label class="nav-overlay-icon" for="__navigation">
        <div class="visually-hidden">Toggle site navigation sidebar</div>
        <i class="icon"><svg><use href="#svg-menu"></use></svg></i>
      </label>
    </div>
    <div class="header-center">
      <a href="../../index.html"><div class="brand">Javet 3.0.0 documentation</div></a>
    </div>
    <div class="header-right">
      <div class="theme-toggle-container theme-toggle-header">
        <button class="theme-toggle">
          <div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
          <svg class="theme-icon-when-auto"><use href="#svg-sun-half"></use></svg>
          <svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
          <svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
        </button>
      </div>
      <label class="toc-overlay-icon toc-header-icon" for="__toc">
        <div class="visually-hidden">Toggle table of contents sidebar</div>
        <i class="icon"><svg><use href="#svg-toc"></use></svg></i>
      </label>
    </div>
  </header>
  <aside class="sidebar-drawer">
    <div class="sidebar-container">
      
      <div class="sidebar-sticky"><a class="sidebar-brand" href="../../index.html">
  
  <div class="sidebar-logo-container">
    <img class="sidebar-logo" src="../../_static/logo.png" alt="Logo"/>
  </div>
  
  <span class="sidebar-brand-text">Javet 3.0.0 documentation</span>
  
</a><form class="sidebar-search-container" method="get" action="../../search.html" role="search">
  <input class="sidebar-search" placeholder="Search" name="q" aria-label="Search">
  <input type="hidden" name="check_keywords" value="yes">
  <input type="hidden" name="area" value="default">
</form>
<div id="searchbox"></div><div class="sidebar-scroll"><div class="sidebar-tree">
  <ul class="current">
<li class="toctree-l1 has-children"><a class="reference internal" href="../../tutorial/index.html">Tutorial</a><input class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" role="switch" type="checkbox"/><label for="toctree-checkbox-1"><div class="visually-hidden">Toggle navigation of Tutorial</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../tutorial/basic/index.html">Basic</a><input class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" role="switch" type="checkbox"/><label for="toctree-checkbox-2"><div class="visually-hidden">Toggle navigation of Basic</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/installation.html">Installation</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/hello_javet.html">Hello Javet</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/javet_shell.html">Javet Shell</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/interception.html">Interception</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/engine_pool.html">Javet Engine Pool</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/node_js_mode_and_v8_mode.html">Node.js Mode and V8 Mode</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/spring_integration.html">Spring Integration</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/polyfill.html">Polyfill</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../tutorial/advanced/index.html">Advanced</a><input class="toctree-checkbox" id="toctree-checkbox-3" name="toctree-checkbox-3" role="switch" type="checkbox"/><label for="toctree-checkbox-3"><div class="visually-hidden">Toggle navigation of Advanced</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/advanced/interact_with_node_js.html">Interact with Node.js</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/advanced/object_converter.html">Object Converter</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/advanced/java_and_javascript_interop.html">Java and JavaScript Interop</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/advanced/expose_json_node_in_v8.html">Expose JsonNode in V8</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../tutorial/migration_guides/index.html">Migration Guides</a><input class="toctree-checkbox" id="toctree-checkbox-4" name="toctree-checkbox-4" role="switch" type="checkbox"/><label for="toctree-checkbox-4"><div class="visually-hidden">Toggle navigation of Migration Guides</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/migration_guides/migrate_from_j2v8.html">Migrate from J2V8</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1 current has-children"><a class="reference internal" href="../index.html">Reference</a><input checked="" class="toctree-checkbox" id="toctree-checkbox-5" name="toctree-checkbox-5" role="switch" type="checkbox"/><label for="toctree-checkbox-5"><div class="visually-hidden">Toggle navigation of Reference</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../javadoc/index.html">API Reference</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../v8_values/index.html">V8 Values</a><input class="toctree-checkbox" id="toctree-checkbox-6" name="toctree-checkbox-6" role="switch" type="checkbox"/><label for="toctree-checkbox-6"><div class="visually-hidden">Toggle navigation of V8 Values</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../v8_values/v8_collection.html">V8 Collection</a></li>
<li class="toctree-l3"><a class="reference internal" href="../v8_values/v8_function.html">V8 Function</a></li>
<li class="toctree-l3"><a class="reference internal" href="../v8_values/v8_promise.html">V8 Promise</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../converters/index.html">Converters</a><input class="toctree-checkbox" id="toctree-checkbox-7" name="toctree-checkbox-7" role="switch" type="checkbox"/><label for="toctree-checkbox-7"><div class="visually-hidden">Toggle navigation of Converters</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../converters/primitive_converter.html">Primitive Converter</a></li>
<li class="toctree-l3"><a class="reference internal" href="../converters/object_converter.html">Object Converter</a></li>
<li class="toctree-l3"><a class="reference internal" href="../converters/proxy_converter.html">Proxy Converter</a></li>
<li class="toctree-l3"><a class="reference internal" href="../converters/bridge_converter.html">Bridge Converter</a></li>
<li class="toctree-l3"><a class="reference internal" href="../converters/custom_converter.html">Custom Converter</a></li>
</ul>
</li>
<li class="toctree-l2 current has-children"><a class="reference internal" href="index.html">Resource Management</a><input checked="" class="toctree-checkbox" id="toctree-checkbox-8" name="toctree-checkbox-8" role="switch" type="checkbox"/><label for="toctree-checkbox-8"><div class="visually-hidden">Toggle navigation of Resource Management</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="load_and_unload.html">Load and Unload</a></li>
<li class="toctree-l3"><a class="reference internal" href="lock.html">Know the Lock</a></li>
<li class="toctree-l3"><a class="reference internal" href="memory_management.html">Memory Management</a></li>
<li class="toctree-l3 current current-page"><a class="current reference internal" href="#">Modularization</a></li>
<li class="toctree-l3"><a class="reference internal" href="performance.html">Javet Performance</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../troubleshooting/index.html">Troubleshooting</a><input class="toctree-checkbox" id="toctree-checkbox-9" name="toctree-checkbox-9" role="switch" type="checkbox"/><label for="toctree-checkbox-9"><div class="visually-hidden">Toggle navigation of Troubleshooting</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../troubleshooting/error_codes.html">Error Codes</a></li>
<li class="toctree-l3"><a class="reference internal" href="../troubleshooting/logging.html">Logging</a></li>
<li class="toctree-l3"><a class="reference internal" href="../troubleshooting/termination.html">Termination</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../tips/index.html">Tips</a><input class="toctree-checkbox" id="toctree-checkbox-10" name="toctree-checkbox-10" role="switch" type="checkbox"/><label for="toctree-checkbox-10"><div class="visually-hidden">Toggle navigation of Tips</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../tips/best_practices.html">Best Practices</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../todo_list.html">TODO List</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../../release_notes/index.html">Release Notes</a><input class="toctree-checkbox" id="toctree-checkbox-11" name="toctree-checkbox-11" role="switch" type="checkbox"/><label for="toctree-checkbox-11"><div class="visually-hidden">Toggle navigation of Release Notes</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="../../release_notes/release_notes_3_0.html">Release Notes 3.0.x</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../../faq/index.html">FAQ</a><input class="toctree-checkbox" id="toctree-checkbox-12" name="toctree-checkbox-12" role="switch" type="checkbox"/><label for="toctree-checkbox-12"><div class="visually-hidden">Toggle navigation of FAQ</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../faq/background/index.html">Background</a><input class="toctree-checkbox" id="toctree-checkbox-13" name="toctree-checkbox-13" role="switch" type="checkbox"/><label for="toctree-checkbox-13"><div class="visually-hidden">Toggle navigation of Background</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../faq/background/history_with_j2v8.html">History with J2V8</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/background/what_is_the_motivation.html">What is the Motivation?</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../faq/development/index.html">Development</a><input class="toctree-checkbox" id="toctree-checkbox-14" name="toctree-checkbox-14" role="switch" type="checkbox"/><label for="toctree-checkbox-14"><div class="visually-hidden">Toggle navigation of Development</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../faq/development/how_to_think_in_javet.html">How to Think in Javet?</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/development/where_are_es6_api_in_v8_mode.html">Where are ES6 API in V8 Mode?</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/development/where_are_the_examples.html">Where are the Examples?</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/development/why_is_the_inspector_disabled_in_node_js_mode.html">Why is the Inspector Disabled in Node.js Mode?</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../faq/environment/index.html">Environment</a><input class="toctree-checkbox" id="toctree-checkbox-15" name="toctree-checkbox-15" role="switch" type="checkbox"/><label for="toctree-checkbox-15"><div class="visually-hidden">Toggle navigation of Environment</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../faq/environment/can_javet_support_legacy_linux.html">Can Javet Support Legacy Linux?</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../faq/troubleshooting/index.html">Troubleshooting</a><input class="toctree-checkbox" id="toctree-checkbox-16" name="toctree-checkbox-16" role="switch" type="checkbox"/><label for="toctree-checkbox-16"><div class="visually-hidden">Toggle navigation of Troubleshooting</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../faq/troubleshooting/a_dynamic_link_library_dll_initialization_routine_failed.html">A dynamic link library (DLL) initialization routine failed</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/troubleshooting/can_i18n_be_supported.html">Can i18n be Supported?</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/troubleshooting/can_i_debug_javet_in_chrome_dev_tools.html">Can I Debug Javet in Chrome DevTools?</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/troubleshooting/why_node_js_crashes_when_being_closed.html">Why Node.js Crashes When being Closed?</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../../development/index.html">Development</a><input class="toctree-checkbox" id="toctree-checkbox-17" name="toctree-checkbox-17" role="switch" type="checkbox"/><label for="toctree-checkbox-17"><div class="visually-hidden">Toggle navigation of Development</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="../../development/tools.html">Development Tools</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../development/build.html">Build Javet</a><input class="toctree-checkbox" id="toctree-checkbox-18" name="toctree-checkbox-18" role="switch" type="checkbox"/><label for="toctree-checkbox-18"><div class="visually-hidden">Toggle navigation of Build Javet</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../development/build_javet_with_docker.html">Build Javet with Docker</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../development/build_javet_from_scratch.html">Build Javet from Scratch</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../development/test.html">Test Javet</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../development/design.html">Javet Design</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../development/performance.html">Javet Performance</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../development/debug_with_chrome_developer_tools.html">Debug with Chrome Developer Tools</a></li>
</ul>
</li>
</ul>

</div>
</div>

      </div>
      
    </div>
  </aside>
  <div class="main">
    <div class="content">
      <div class="article-container">
        <a href="#" class="back-to-top muted-link">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
            <path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12z"></path>
          </svg>
          <span>Back to top</span>
        </a>
        <div class="content-icon-container">
          
<div class="theme-toggle-container theme-toggle-content">
            <button class="theme-toggle">
              <div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
              <svg class="theme-icon-when-auto"><use href="#svg-sun-half"></use></svg>
              <svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
              <svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
            </button>
          </div>
          <label class="toc-overlay-icon toc-content-icon" for="__toc">
            <div class="visually-hidden">Toggle table of contents sidebar</div>
            <i class="icon"><svg><use href="#svg-toc"></use></svg></i>
          </label>
        </div>
        <article role="main">
          <section id="modularization">
<h1>Modularization<a class="headerlink" href="#modularization" title="Link to this heading">#</a></h1>
<section id="node-js-mode">
<h2>Node.js Mode<a class="headerlink" href="#node-js-mode" title="Link to this heading">#</a></h2>
<section id="example">
<h3>Example<a class="headerlink" href="#example" title="Link to this heading">#</a></h3>
<p>In Node.js mode, Javet leaves Node.js with its own ways of handling modules. The coding experience is identical to the one in Node.js and applications can get all features supported by Javet, like function interception. Here is an example.</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="w"> </span><span class="p">(</span><span class="n">JavetEnginePool</span><span class="o">&lt;</span><span class="n">NodeRuntime</span><span class="o">&gt;</span><span class="w"> </span><span class="n">javetEnginePool</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">JavetEnginePool</span><span class="o">&lt;</span><span class="n">NodeRuntime</span><span class="o">&gt;</span><span class="p">())</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="n">javetEnginePool</span><span class="p">.</span><span class="na">getConfig</span><span class="p">().</span><span class="na">setJSRuntimeType</span><span class="p">(</span><span class="n">JSRuntimeType</span><span class="p">.</span><span class="na">Node</span><span class="p">);</span>
<span class="w">    </span><span class="k">try</span><span class="w"> </span><span class="p">(</span><span class="n">IJavetEngine</span><span class="o">&lt;</span><span class="n">NodeRuntime</span><span class="o">&gt;</span><span class="w"> </span><span class="n">iJavetEngine</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">javetEnginePool</span><span class="p">.</span><span class="na">getEngine</span><span class="p">())</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="n">NodeRuntime</span><span class="w"> </span><span class="n">nodeRuntime</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">iJavetEngine</span><span class="p">.</span><span class="na">getV8Runtime</span><span class="p">();</span>
<span class="w">        </span><span class="n">File</span><span class="w"> </span><span class="n">workingDirectory</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">File</span><span class="p">(</span><span class="n">JavetOSUtils</span><span class="p">.</span><span class="na">WORKING_DIRECTORY</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;scripts/node/test-node&quot;</span><span class="p">);</span>
<span class="w">        </span><span class="c1">// Set the require root directory so that Node.js is able to locate node_modules.</span>
<span class="w">        </span><span class="n">nodeRuntime</span><span class="p">.</span><span class="na">getNodeModule</span><span class="p">(</span><span class="n">NodeModuleModule</span><span class="p">.</span><span class="na">class</span><span class="p">).</span><span class="na">setRequireRootDirectory</span><span class="p">(</span><span class="n">workingDirectory</span><span class="p">);</span>
<span class="w">        </span><span class="n">getLogger</span><span class="p">().</span><span class="na">logInfo</span><span class="p">(</span><span class="s">&quot;1.23 + 2.34 = {0}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">nodeRuntime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span>
<span class="w">                </span><span class="s">&quot;const Decimal = require(&#39;decimal.js&#39;);&quot;</span><span class="w"> </span><span class="o">+</span>
<span class="w">                        </span><span class="s">&quot;const a = new Decimal(1.23);&quot;</span><span class="w"> </span><span class="o">+</span>
<span class="w">                        </span><span class="s">&quot;const b = new Decimal(2.34);&quot;</span><span class="w"> </span><span class="o">+</span>
<span class="w">                        </span><span class="s">&quot;a.add(b).toString();&quot;</span><span class="p">).</span><span class="na">executeString</span><span class="p">());</span>
<span class="w">    </span><span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
</section>
<section id="gaps-between-javet-node-js-mode-and-native-node-js">
<h3>Gaps between Javet Node.js Mode and Native Node.js<a class="headerlink" href="#gaps-between-javet-node-js-mode-and-native-node-js" title="Link to this heading">#</a></h3>
<div class="table-wrapper docutils container">
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Feature</p></th>
<th class="head"><p>Javet Node.js Mode</p></th>
<th class="head"><p>Native Node.js</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">require()</span></code> Root</p></td>
<td><p>Java Application Working Directory</p></td>
<td><p>JavaScript Application Working Directory</p></td>
</tr>
<tr class="row-odd"><td><p>Working Directory</p></td>
<td><p>Java Application Working Directory</p></td>
<td><p>JavaScript Application Working Directory</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">__dirname</span></code></p></td>
<td><p>N/A</p></td>
<td><p>Yes</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">__filename</span></code></p></td>
<td><p>N/A</p></td>
<td><p>Yes</p></td>
</tr>
<tr class="row-even"><td><p>Module Mode</p></td>
<td><p>default: false</p></td>
<td><p>default: true</p></td>
</tr>
</tbody>
</table>
</div>
<p>Usually the Java application working directory doesn't contain <code class="docutils literal notranslate"><span class="pre">node_modules</span></code>. That for sure breaks Node.js. No worry, here are the steps on closing the gaps.</p>
<ol class="arabic simple">
<li><p>Set the <code class="docutils literal notranslate"><span class="pre">require()</span></code> root directory so that Node.js is able to locate <code class="docutils literal notranslate"><span class="pre">node_modules</span></code>.</p></li>
<li><p>Set working directory to where the script is located.</p></li>
<li><p>Set <code class="docutils literal notranslate"><span class="pre">__dirname</span></code>.</p></li>
<li><p>Set <code class="docutils literal notranslate"><span class="pre">__filename</span></code>.</p></li>
</ol>
<p>Luckily, in Javet, when <code class="docutils literal notranslate"><span class="pre">getExecutor(File</span> <span class="pre">scriptFile)</span></code> or <code class="docutils literal notranslate"><span class="pre">getExecutor(Path</span> <span class="pre">scriptPath)</span></code> is called, all these 4 steps are automatically performed. If <code class="docutils literal notranslate"><span class="pre">getExecutor(String</span> <span class="pre">scriptString)</span></code> is called, obviously Javet doesn't know what to do, but application may call <code class="docutils literal notranslate"><span class="pre">IV8Executor.setResourceName(String</span> <span class="pre">resourceName)</span></code> later to perform these 4 steps. So, Javet Node.js mode doesn't care where the script comes from. Application may feel free to virtualize Node.js.</p>
<p>Can Javet run script in Node.js Module Mode? Yes, just call <code class="docutils literal notranslate"><span class="pre">IV8Executor.setModule(true)</span></code>.</p>
<p>The exciting thing is: in Javet, applications may have multiple instances of Node.js pointing to different <code class="docutils literal notranslate"><span class="pre">node_modules</span></code> and potentially these Node.js instances can share the same piece of data.</p>
</section>
<section id="deal-with-native-modules">
<h3>Deal with Native Modules<a class="headerlink" href="#deal-with-native-modules" title="Link to this heading">#</a></h3>
<p>Node.js native modules usually cannot be dynamically loaded to Javet. E.g. sqlite3. That issue also bothers Electron. Electron folks created project <a class="reference external" href="https://github.com/electron/electron-rebuild">electron-rebuild</a> which rebuilds the native modules from source code and its own native symbols.</p>
<p>Javet follows the same approach on Windows, and a simpler approach on Linux.</p>
<section id="patch-elf-native-modules-on-linux">
<h4>Patch ELF Native Modules on Linux<a class="headerlink" href="#patch-elf-native-modules-on-linux" title="Link to this heading">#</a></h4>
<p>The native modules on Linux don't know the existence of Javet. When they look up Node.js symbols which are provided by Javet, they just fail with errors like the following.</p>
<blockquote>
<div><p>com.caoccao.javet.exceptions.JavetExecutionException: Error: /....../node_modules/sqlite3/lib/binding/napi-v3-linux-x64/node_sqlite3.node: undefined symbol: napi_create_error</p>
</div></blockquote>
<p>The fix is very simple. Here is a sample sqlite3.</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="c1"># Install patchelf on Ubuntu (Optional)</span>
sudo<span class="w"> </span>apt<span class="w"> </span>install<span class="w"> </span>patchelf
<span class="nb">cd</span><span class="w"> </span>scripts/node
<span class="c1"># Install sqlite3</span>
npm<span class="w"> </span>install
<span class="nb">cd</span><span class="w"> </span>javet-rebuild
<span class="nb">export</span><span class="w"> </span><span class="nv">NODE_MODULE_FILE</span><span class="o">=</span><span class="s2">&quot;../node_modules/sqlite3/lib/binding/napi-v3-linux-x64/node_sqlite3.node&quot;</span>
./rebuild.sh
</pre></div>
</div>
<p>The <a class="reference external" href="https://github.com/caoccao/Javet/tree/main/1/2/3/../../../scripts/node/javet-rebuild/rebuild.sh">rebuild.sh</a> actually calls <a class="reference external" href="https://github.com/NixOS/patchelf">patchelf</a> to add Javet to the node module's dependency.</p>
</section>
<section id="rebuild-native-modules-on-windows">
<h4>Rebuild Native Modules on Windows<a class="headerlink" href="#rebuild-native-modules-on-windows" title="Link to this heading">#</a></h4>
<p>The native modules on Windows don't know the existence of Javet. Windows dynamic library loading API <code class="docutils literal notranslate"><span class="pre">LoadLibraryExW</span></code> throws the following error.</p>
<blockquote>
<div><p>A dynamic link library (DLL) initialization routine failed.</p>
</div></blockquote>
<p>The fix is a bit complicated.</p>
<ul class="simple">
<li><p>Prepare the Windows build environment by following <a class="reference internal" href="../../development/build.html"><span class="doc">Build Javet</span></a>.</p></li>
<li><p>Install the node modules from source code <code class="docutils literal notranslate"><span class="pre">npm</span> <span class="pre">install</span> <span class="pre">--build-from-source</span></code>.</p></li>
<li><p>Download the corresponding Javet library file from this <a class="reference external" href="https://drive.google.com/drive/folders/18wcF8c-zjZg9iZeGfNSL8-bxqJwDZVEL?usp=sharing">drive</a>.</p></li>
<li><p>Unzip the Javet library file somewhere.</p></li>
<li><p>Create a rebuild script pointing to the Javet library file by referencing <a class="reference external" href="https://github.com/caoccao/Javet/tree/main/1/2/3/../../../scripts/node/javet-rebuild/rebuild-sqlite3.cmd">rebuild-sqlite3.cmd</a> and <a class="reference external" href="https://github.com/caoccao/Javet/tree/main/1/2/3/../../scripts/node/javet-rebuild/rebuild.cmd">rebuild.cmd</a>.</p></li>
<li><p>Run the rebuild script.</p></li>
</ul>
<p>The rebuild script actually replaces <code class="docutils literal notranslate"><span class="pre">node.lib</span></code> with <code class="docutils literal notranslate"><span class="pre">libjavet....lib</span></code> during the rebuild so that the new node modules can tell <code class="docutils literal notranslate"><span class="pre">LoadLibraryExW</span></code> to look for Javet instead of Node.js.</p>
<p>Javet calls for someone who can voluntarily host the Javet libraries and Javet compatible node modules so that major Javet users don't need to go through these. For now, it has to be a pretty manual work.</p>
<div class="admonition caution">
<p class="admonition-title">Caution</p>
<p>Make Backups</p>
<p>Once the node modules are patched or rebuilt, they can only be loaded by that particular version of Javet and they cannot be loaded by Node.js any more.</p>
</div>
<p>Before the rebuild script is executed, the imports look like the following:</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>dumpbin /imports node_modules\sqlite3\lib\binding\napi-v3-win32-x64\node_sqlite3.node

Section contains the following delay load imports:

node.exe
          00000001 Characteristics
  0000000180154A40 Address of HMODULE
  0000000180154818 Import Address Table
  000000018014F248 Import Name Table
  000000018014FA68 Bound Import Name Table
  0000000000000000 Unload Import Name Table
                 0 time date stamp

                                0000000180108724  424B napi_create_function
                                ...
                                0000000180108AB5  4243 napi_create_buffer_copy
</pre></div>
</div>
<p>After the rebuild script is executed, the imports look like the following:</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>dumpbin /imports node_modules\sqlite3\lib\binding\napi-v3-win32-x64\node_sqlite3.node

Section contains the following delay load imports:

libjavet-node-windows-x86_64.v.x.x.x.dll
         1801363D8 Import Address Table
         180166610 Import Name Table
                 0 time date stamp
                 0 Index of first forwarder reference

                    6096 napi_open_escapable_handle_scope
                    ...
                    6072 napi_get_undefined
</pre></div>
</div>
</section>
<section id="manual-patch-native-modules-on-windows">
<h4>Manual Patch Native Modules on Windows<a class="headerlink" href="#manual-patch-native-modules-on-windows" title="Link to this heading">#</a></h4>
<p>Apart from rebuilding the native modules on Windows, there is also a manual way of patching the native modules. Let's see how to patch <code class="docutils literal notranslate"><span class="pre">&#64;swc/core</span></code> which doesn't support <code class="docutils literal notranslate"><span class="pre">node-gyp</span></code>.</p>
<ol class="arabic simple">
<li><p>Download <a class="reference external" href="https://www.mzrst.com/">PPEE (Puppy, Professional PE file Explorer)</a>.</p></li>
<li><p>Install SWC via <code class="docutils literal notranslate"><span class="pre">npm</span> <span class="pre">i</span> <span class="pre">&#64;swc/cli</span> <span class="pre">&#64;swc/core</span></code>.</p></li>
<li><p>Drag and drop <code class="docutils literal notranslate"><span class="pre">node_modules\&#64;swc\core-win32-x64-msvc\swc.win32-x64-msvc.node</span></code> to PPEE.</p></li>
<li><p>Navigate to <code class="docutils literal notranslate"><span class="pre">DIRECTORY_ENTRY_DELAY_IMPORT</span></code>.</p></li>
<li><p>Change the DLL name from <code class="docutils literal notranslate"><span class="pre">node.exe</span></code> to <code class="docutils literal notranslate"><span class="pre">libjavet-node-windows-x86_64.v.x.x.x.dll</span></code> where <code class="docutils literal notranslate"><span class="pre">x.x.x</span></code> needs to be replaced with the actual Javet version.</p></li>
<li><p>Save the change.</p></li>
</ol>
</section>
</section>
</section>
<section id="v8-mode">
<h2>V8 Mode<a class="headerlink" href="#v8-mode" title="Link to this heading">#</a></h2>
<p>In V8 mode, there is no out-of-box support to ES6 dynamic import. But, Javet provides complete support on top of V8. There are 2 ways of playing around with the ES6 dynamic import: Pre-load and On-demand.</p>
<section id="pre-load">
<h3>Pre-load<a class="headerlink" href="#pre-load" title="Link to this heading">#</a></h3>
<p>Javet stores compiled modules in a map with key = module path, value = compiled module. When V8 meets a new module to be imported, Javet will look up the map and return the compiled module to V8. So, in order to simulate dynamic import, application needs to compile those required modules before the final execution.</p>
<p>For instance: The dependency is as following.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Application
├─A
│ ├─a.js (depends on b.js)
│ └─B
│   └─b.js
├─C
│ └─c.js
└─d.js
</pre></div>
</div>
<p>The execution steps are as following.</p>
<ol class="arabic simple">
<li><p>Compile module ./A/B/b.js</p></li>
<li><p>Compile module ./A/a.js</p></li>
<li><p>Compile module ./C/c.js</p></li>
<li><p>Compile module ./d.js</p></li>
<li><p>Launch the application</p></li>
</ol>
<p>Here is an example. Assuming <code class="docutils literal notranslate"><span class="pre">test.js</span></code> depends on <code class="docutils literal notranslate"><span class="pre">module.js</span></code>, the code looks like the following.</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">String</span><span class="w"> </span><span class="n">codeString</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;export function testFromModule() { return { a: 1 }; };&quot;</span><span class="p">;</span>
<span class="c1">// Step 1: Assign a resource name to a piece of code.</span>
<span class="n">IV8Executor</span><span class="w"> </span><span class="n">iV8Executor</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="n">codeString</span><span class="p">).</span><span class="na">setResourceName</span><span class="p">(</span><span class="s">&quot;./module.js&quot;</span><span class="p">);</span>
<span class="c1">// Step 2: Compile the module.js.</span>
<span class="k">try</span><span class="w"> </span><span class="p">(</span><span class="n">V8Module</span><span class="w"> </span><span class="n">v8Module</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">iV8Executor</span><span class="p">.</span><span class="na">compileModule</span><span class="p">())</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="c1">// Step 3: Evaluate the module.js.</span>
<span class="w">    </span><span class="n">v8Module</span><span class="p">.</span><span class="na">executeVoid</span><span class="p">();</span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">containsModule</span><span class="p">(</span><span class="s">&quot;./module.js&quot;</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">&quot;./module.js is registered as a module.&quot;</span><span class="p">);</span>
<span class="w">    </span><span class="p">}</span>
<span class="w">    </span><span class="n">codeString</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;import { testFromModule } from &#39;./module.js&#39;; testFromModule();&quot;</span><span class="p">;</span>
<span class="w">    </span><span class="c1">// Step 4: Do the same to test.js.</span>
<span class="w">    </span><span class="n">iV8Executor</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="n">codeString</span><span class="p">).</span><span class="na">setResourceName</span><span class="p">(</span><span class="s">&quot;./test.js&quot;</span><span class="p">).</span><span class="na">setModule</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span>
<span class="w">    </span><span class="c1">// Step 5: Compile and evaluate test.js and Javet will automatically feed V8 with module.js.</span>
<span class="w">    </span><span class="k">try</span><span class="w"> </span><span class="p">(</span><span class="n">V8ValueObject</span><span class="w"> </span><span class="n">v8ValueObject</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">iV8Executor</span><span class="p">.</span><span class="na">execute</span><span class="p">())</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="c1">// Step 6: Verify the module.js taking effect.</span>
<span class="w">        </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">&quot;Variable a = &quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">v8ValueObject</span><span class="p">.</span><span class="na">getInteger</span><span class="p">(</span><span class="s">&quot;a&quot;</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">&quot;.&quot;</span><span class="p">);</span>
<span class="w">    </span><span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
</section>
<section id="on-demand">
<h3>On-demand<a class="headerlink" href="#on-demand" title="Link to this heading">#</a></h3>
<p>Obviously, pre-loading modules requires application to analyze the code for complete dependency. That is too heavy in most of the cases. Luckily, Javet also supports registering a module resolver which is called back when the modules are being imported. With the module resolver, application doesn't need to analyze the code for dependency. Of course, application is responsible for security check.</p>
<p>Here is an example. Assuming <code class="docutils literal notranslate"><span class="pre">test.js</span></code> depends on <code class="docutils literal notranslate"><span class="pre">module.js</span></code>, the code looks like the following.</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="c1">// Step 1: Create a V8 runtime from V8 host in try-with-resource.</span>
<span class="k">try</span><span class="w"> </span><span class="p">(</span><span class="n">V8Runtime</span><span class="w"> </span><span class="n">v8Runtime</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">V8Host</span><span class="p">.</span><span class="na">getV8Instance</span><span class="p">().</span><span class="na">createV8Runtime</span><span class="p">())</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="c1">// Step 2: Register a custom module resolver.</span>
<span class="w">    </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">setV8ModuleResolver</span><span class="p">((</span><span class="n">runtime</span><span class="p">,</span><span class="w"> </span><span class="n">resourceName</span><span class="p">,</span><span class="w"> </span><span class="n">v8ModuleReferrer</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="c1">// Step 3: Compile module.js from source code if the resource name matches.</span>
<span class="w">        </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="s">&quot;./module.js&quot;</span><span class="p">.</span><span class="na">equals</span><span class="p">(</span><span class="n">resourceName</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
<span class="w">            </span><span class="k">return</span><span class="w"> </span><span class="n">runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;export function test() { return 1; }&quot;</span><span class="p">)</span>
<span class="w">                    </span><span class="p">.</span><span class="na">setResourceName</span><span class="p">(</span><span class="n">resourceName</span><span class="p">).</span><span class="na">compileV8Module</span><span class="p">();</span>
<span class="w">        </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<span class="w">            </span><span class="k">return</span><span class="w"> </span><span class="kc">null</span><span class="p">;</span>
<span class="w">        </span><span class="p">}</span>
<span class="w">    </span><span class="p">});</span>
<span class="w">    </span><span class="c1">// Step 4: Import module.js in test.js and expose test() in global context.</span>
<span class="w">    </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;import { test } from &#39;./module.js&#39;; globalThis.test = test;&quot;</span><span class="p">)</span>
<span class="w">            </span><span class="p">.</span><span class="na">setModule</span><span class="p">(</span><span class="kc">true</span><span class="p">).</span><span class="na">setResourceName</span><span class="p">(</span><span class="s">&quot;./test.js&quot;</span><span class="p">).</span><span class="na">executeVoid</span><span class="p">();</span>
<span class="w">    </span><span class="c1">// Step 5: Call test() in global context.</span>
<span class="w">    </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">&quot;test() -&gt; &quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">v8Runtime</span><span class="p">.</span><span class="na">getExecutor</span><span class="p">(</span><span class="s">&quot;test()&quot;</span><span class="p">).</span><span class="na">executeInteger</span><span class="p">());</span>
<span class="p">}</span>
</pre></div>
</div>
<p>It is V8 that performs the dependency analysis. Javet just relays the callback to application and actively caches the compiled modules so that the module resolver is only called one time per module.</p>
</section>
</section>
<section id="internals">
<h2>Internals<a class="headerlink" href="#internals" title="Link to this heading">#</a></h2>
<p>How Javet and V8 work internally for supporting modules can be found at <a class="reference internal" href="../../development/design.html"><span class="doc">Javet Design</span></a>.</p>
<img alt="Javet Module System" src="../../_images/javet_module_system.png" />
<p>Please note that the way Javet handles dynamic import in V8 mode can be applied to Node.js mode. That means all Node.js modules can be virtualized by Javet.</p>
</section>
</section>

        </article>
      </div>
      <footer>
        
        <div class="related-pages">
          <a class="next-page" href="performance.html">
              <div class="page-info">
                <div class="context">
                  <span>Next</span>
                </div>
                <div class="title">Javet Performance</div>
              </div>
              <svg class="furo-related-icon"><use href="#svg-arrow-right"></use></svg>
            </a>
          <a class="prev-page" href="memory_management.html">
              <svg class="furo-related-icon"><use href="#svg-arrow-right"></use></svg>
              <div class="page-info">
                <div class="context">
                  <span>Previous</span>
                </div>
                
                <div class="title">Memory Management</div>
                
              </div>
            </a>
        </div>
        <div class="bottom-of-page">
          <div class="left-details">
            <div class="copyright">
                Copyright &#169; 2021-2023. caoccao.com Sam Cao
            </div>
            Made with 
            <a href="https://github.com/pradyunsg/furo">Furo</a>
            
          </div>
          <div class="right-details">
            
          </div>
        </div>
        
      </footer>
    </div>
    <aside class="toc-drawer">
      
      
      <div class="toc-sticky toc-scroll">
        <div class="toc-title-container">
          <span class="toc-title">
            On this page
          </span>
        </div>
        <div class="toc-tree-container">
          <div class="toc-tree">
            <ul>
<li><a class="reference internal" href="#">Modularization</a><ul>
<li><a class="reference internal" href="#node-js-mode">Node.js Mode</a><ul>
<li><a class="reference internal" href="#example">Example</a></li>
<li><a class="reference internal" href="#gaps-between-javet-node-js-mode-and-native-node-js">Gaps between Javet Node.js Mode and Native Node.js</a></li>
<li><a class="reference internal" href="#deal-with-native-modules">Deal with Native Modules</a><ul>
<li><a class="reference internal" href="#patch-elf-native-modules-on-linux">Patch ELF Native Modules on Linux</a></li>
<li><a class="reference internal" href="#rebuild-native-modules-on-windows">Rebuild Native Modules on Windows</a></li>
<li><a class="reference internal" href="#manual-patch-native-modules-on-windows">Manual Patch Native Modules on Windows</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#v8-mode">V8 Mode</a><ul>
<li><a class="reference internal" href="#pre-load">Pre-load</a></li>
<li><a class="reference internal" href="#on-demand">On-demand</a></li>
</ul>
</li>
<li><a class="reference internal" href="#internals">Internals</a></li>
</ul>
</li>
</ul>

          </div>
        </div>
      </div>
      
      
    </aside>
  </div>
</div><script src="../../_static/documentation_options.js?v=5e0dd536"></script>
    <script src="../../_static/doctools.js?v=888ff710"></script>
    <script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="../../_static/scripts/furo.js?v=32e29ea5"></script>
    <script src="../../_static/tabs.js?v=3ee01567"></script>
    </body>
</html>